import React, { Component, createRef } from 'react'
import PropTypes from "prop-types"
import { Form, Input } from "antd"
/**
 * 添加分类的form组件
 */
const Item = Form.Item;
export default class AddForm extends Component {
    constructor(props) {
        super(props);
        // 创建一个 ref
        this.formRef = createRef();
    }

    //对props的值进行限制
    static propTypes = {
        setForm: PropTypes.func.isRequired    //用来传递form对象实例的函数
    }
    componentDidMount() {
        const formInstance = this.formRef.current;
        if (formInstance) {
            //将form对象通过setForm()传递父组件
            this.props.setForm(formInstance)
        }
    }

    render() {
        return (
            <Form name="addForm" style={{ maxWidth: 360 }} ref={this.formRef} labelCol={{ span: 6 }} wrapperCol={{ span: 18}}
                initialValues={{
                    roleName:""
                }}>

                <Item label="角色名称" name="roleName" rules={[
                    {
                        required: true,
                        message: '请输入角色的名称!',
                    },
                ]} >
                    <Input placeholder='请输入角色的名称'></Input>
                </Item>
            </Form>
        )
    }
}


